package com.gjt.serverSocket;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.CompletionHandler;
import java.nio.channels.WritableByteChannel;

public class LineHandler implements CompletionHandler<Integer, ByteBuffer> {

    @Override
    public void completed(Integer result, ByteBuffer attachment) {
        attachment.flip();
        WritableByteChannel out = Channels.newChannel(System.out);
        try {
            out.write(attachment);
        } catch (IOException e) {
            System.out.println(e);
        }
    }

    @Override
    public void failed(Throwable exc, ByteBuffer attachment) {
        System.out.println("读取失败" + exc);
    }



}
